package com.xbongbong.pro.statistic.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 指标类型枚举
 *
 * @author zcp
 * @date 2019/1/11
 * @since v1.0
 * @version v1.0
 */
@Getter
public enum StatisticsTypeEnum {
    /**
     * 系统指标
     */
    SYSTEM_STATISTIC(1, "enum.statisticsType.name.system_statistic"),
    /**
     * 自定义指标
     */
    CUSTOM_STATISTIC(2, "enum.statisticsType.name.custom_statistic"),
    /**
     * 所有指标，查询所有指标时会用到
     */
    ALL(3, "enum.statisticsType.name.all_statistic"),
    /**
     * 防错
     */
    UNKNOWN(404,"404")
    ;

    /**
     * 指标类型code值，对应tb_chart内的statistics_type值
     */
    private int code;
    /**
     * 类型描述
     */
    private String name;

    StatisticsTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code
     * @return IndexTypeEnum
     */
    public static StatisticsTypeEnum getByCode(Integer code) {
        for (StatisticsTypeEnum cacheCode : values()) {
            if (Objects.equals(cacheCode.getCode(), code)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    public static List<Integer> getStatisticTypes() {
        return Arrays.asList(SYSTEM_STATISTIC.getCode(),CUSTOM_STATISTIC.getCode());
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
